package bairui.international.weixin.portal.miniapp.util;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

import org.elasticsearch.client.RestHighLevelClient;

import bairui.international.model.domain.jpa.TB_Town;
import bairui.international.service.Service_City;
import bairui.international.service.Service_Province;
import bairui.international.service.Service_Town;

public class Util_ElasticSearch {

	/**
     * 将pump数据导入到ElasticSearch中
     */
	public static void init(RestHighLevelClient client, Service_Province service_Province, Service_City service_City, Service_Town service_Town) throws IOException{
		System.out.println("====ElasticSearch==开始初始化====");
    	/*
    	 * 收集数据
    	 */
		List<TB_Town> datas = DataDeal
			.gainData(service_Province, service_City, service_Town)
			.stream()
			.flatMap(it->it.getCities().stream())
			.flatMap(it->it.getTowns().stream())
			.collect(Collectors.toList());
    	/*
    	 * 处理ElasticSearch
    	 */
		ElasticSearchDeal.indexDeal(client, datas);
		//
		System.out.println("====ElasticSearch==初始化完成====");
	}
	
}
